package com.my.controller;


import com.alibaba.fastjson.JSONObject;
import com.my.bean.*;
import com.my.service.WorkguidaceService;
import com.my.util.SessionUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * <p>
 * 日常护理工作指导内容  前端控制器
 * </p>
 *
 * @author 闫亚茹
 * @since 2018-08-24
 */
@Controller
@RequestMapping("/workguidace")
public class WorkguidaceController {
	@Autowired
    WorkguidaceService workguidaceService;
Logger logger=Logger.getLogger(WorkguidaceController.class);


    /**
     * 添加
     * @param param
     * @return
     */
	@RequestMapping("/addWorkguidace")
    @ResponseBody
    public String addWorkguidace( String param,HttpSession session){
        Workguidace workguidace=JSONObject.parseObject(param,Workguidace.class);
        workguidace.setDate(new Date().getTime());
        workguidace.setIsDelete(2);
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        workguidace.setAreaid(areaid);
        if (workguidaceService.insert(workguidace)){
            logger.info("{addWorkguidace|保存成功}");
            return "保存成功";

        }else {
            logger.info("{addWorkguidace|添加失败}");
            return "添加失败";
        }

    }
    /**
     * 查询
     * @param voPage
     * @return
     */
    @RequestMapping("/selectWorkguidace")
    @ResponseBody
    public ResultPage<Workguidace> selectWorkguidace(String lin, String data, VoPage voPage, HttpSession session ){
        boolean admin=false;
//如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }


        Map map=new HashMap();
        map.put("lin",lin);
        map.put("data",data);
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        ResultPage<Workguidace> resultPage = workguidaceService.selectMyPage(map,voPage,areaid,admin);
        return resultPage;
    }

    /**
     * 日常护理记录 前台页面
     * @return
     */
    @RequestMapping("/guidace")
    public String Workguidace (){
        return "Payment_Configure";
    }


    /**
     * 删除日常护理记录
     */
    @RequestMapping("/deleteWorkguidace")
    @ResponseBody
    public boolean deleteWorkguidace(Long id){
        return workguidaceService.deleteById(id);
    }

    /**
     * 修改日常护理记录
     * @return
     */
    @RequestMapping("/updateWorkguidace")
    @ResponseBody
    public String updateWorkguidace(String param){
        List<Workguidace> list  = new ArrayList<>();
        Workguidace workguidace=JSONObject.parseObject(param,Workguidace.class);
        list.add(workguidace);
        if(workguidaceService.updateBatchById(list)){
            return "修改成功";
        }else{
            return "修改失败";
        }
    }
  @RequestMapping("workgui_Add")
    public String workgui_Add(){
        return "/Alert/workgui_Add";
  }

@RequestMapping("workgui_Edit")
    public String workgui_Edit(){
        return "/Alert/workgui_Edit";
}


/**
 * 返回编辑表格
 */
@RequestMapping("/nurse")
    public String  nurse(){
    return  "nurse";
}


}
